import { Component, OnInit,AfterViewInit } from '@angular/core';
import {Validators,FormGroup,FormControl,FormArray} from "@angular/forms";
import {validateEmail} from "../../validate";

@Component({
  selector: 'app-form',
  templateUrl: './form.component.html',
  styleUrls: ['./form.component.css']
})
export class FormComponent implements OnInit {
  private data;
  private sexs=[{id:null,title:'选择'},{id:1,title:'男'},{id:2,title:'女'},{id:3,title:'3'}];
  private curnum=1;
  private userForm=new FormGroup({
    name4:new FormControl('',[Validators.required,Validators.minLength(2),validateEmail]),
    age4:new FormControl('',[Validators.required]),
    users:new FormArray([
        new FormControl('a'),new FormControl('b')
    ])
  })
  constructor() { }

  ngOnInit() {
  	this.data={name:'',age:'',sex:'',num:null,sexs:[]}
    setTimeout(()=>{
      this.sexs[1].title='男2'
    },1000)
  }
  submit(name,age,sex,form){
  	this.data.name=name;
  	this.data.age=age;
  	this.data.sex=sex;
  	console.log(form);
  }
  onSubmit(form){
  	if(form.form.valid==false){
  		alert('请正确填写')
  	}
  }
  submit3(form,namegroup,sexgroup){
    console.log(form,namegroup,sexgroup);
  }
  next(num){
    this.curnum=num;
  }
  submit4(form){
    console.log(form);
    console.log(this.userForm)
  }

}
